package com.queue.rabbitmq.listener;

import org.springframework.amqp.core.ExchangeTypes;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;


@Component
public class PublishReceiveListener {

    @RabbitListener(queues = "queue_fanout1")
    public void receiveMessage1(String msg) {
        System.out.println("队列1接收到的消息：" + msg);
    }


    @RabbitListener(queues = "queue_fanout2")
    public void receiveMessage2(String msg) {
        System.out.println("队列2接收到的消息：" + msg);
    }

    /**
     * 其他客户端需要接收广播消息
     * @param msg
     */
    @RabbitListener(bindings = @QueueBinding(value = @Queue(name = "queue_fanout3"), exchange = @Exchange(name = "exchange_fanout",type = ExchangeTypes.FANOUT)))
    public void receiveMessage3(String msg) {
        System.out.println("队列3接收到的消息：" + msg);
    }
}
